<?php

/**
 * 默认控制器
 */
class Controller_Default extends Controller_Abstract
{
    function actionIndex()
    {   exit;
        set_time_limit(0);
    	/* // 为 $this->_view 指定的值将会传递数据到视图中
		# $this->_view['text'] = 'Hello!';
		$ch= curl_init();
		curl_setopt($ch,CURLOPT_URL,'http://www.hdjr.org/2013-6-24.html');
		curl_setopt($ch,CURLOPT_HEADER,1);
    	$content=curl_exec($ch); 
    	print_r($content);
    	*/
        require_once 'D:\www\root\chief\lib\htmlparse/simple_html_dom.php';
        $a=strtotime("2013-1-1");
        for($j=0;$j<=2921;$j++){
        $b=strtotime("+{$j} day", $a);
        $date=date('Y-n-j',$b);   	
    	$html = file_get_html("http://www.hdjr.org/{$date}.html");
        $element=$html->find('.chiefA',0)->find('ul.NL',0)->find('li');
        $data=array();
        $i=0;
        foreach($element as $k)
        {  
           $data[]=$k->plaintext;           
        }
        $num=count($data)/2;
        for($i=1;$i<=$num;$i++)
        {
          $rili[trim(str_replace('：','',$data[2*$i - 2]))]=$data[2*$i-1];
        }
        
        $element2=$html->find('ul.JS',0)->find('li');
        foreach($element2 as $k2)
        {
          $data2[]=$k2->plaintext;
        }
        $datanew=array_merge($rili,$data2);
        print_r($datanew);die;
        
        
        exit;
        $lan=array(1 =>'公历',2=>'回历',3=>'农历',4=>'胎神占方',5=>'岁次',6=>'彭祖百忌',7=>'五行',8=>'吉神宜趋',9=>'冲煞',10=>'凶神宜忌',11=>'宜',12=>'忌');   
        $goodday = new Exgoodday();
        $goodday->gongli =$rili[$lan[1]];
        $goodday->nongli =$rili[$lan[3]];     
        $goodday->sueici =$rili[$lan[5]];
        $goodday->wuxing =$rili[$lan[7]];
        $goodday->chong  =$rili[$lan[9]];
        $goodday->taishen  =$rili[$lan[4]];
        $goodday->jishen  =$rili[$lan[8]];
        $goodday->pengzu =$rili[$lan[6]];
        $goodday->yi     =$rili[$lan[11]];
        $goodday->xiongshen  =$rili[$lan[10]];
        $goodday->a   =$rili[0];
        $goodday->a1   =$rili[1];                
        $goodday->a2   =$rili[2];
        $goodday->b   =$rili[3];
        $goodday->b1   =$rili[4];
        $goodday->b2   =$rili[5];
        $goodday->c   =$rili[6];
        $goodday->c1   =$rili[7];
        $goodday->c2   =$rili[8];
        $goodday->d   =$rili[9];
        $goodday->d1   =$rili[11];
        $goodday->d2   =$rili[12];
        $goodday->e   =$rili[13];
        $goodday->e1   =$rili[14];
        $goodday->e2   =$rili[15];
        $goodday->f   =$rili[16];
        $goodday->f1   =$rili[17];
        $goodday->f2   =$rili[18];
        $goodday->g   =$rili[19];
        $goodday->g1   =$rili[20];
        $goodday->g2   =$rili[21];
        $goodday->h   =$rili[22];
        $goodday->h1   =$rili[23];
        $goodday->h2   =$rili[24];
        $goodday->i   =$rili[25];
        $goodday->i1   =$rili[26];
        $goodday->i2   =$rili[27];
        $goodday->j   =$rili[28];
        $goodday->j1   =$rili[29];
        $goodday->j2   =$rili[30];
        $goodday->k   =$rili[31];
        $goodday->k1   =$rili[32];
        $goodday->k2   =$rili[33];
        $goodday->l   =$rili[34];
        $goodday->l1   =$rili[35];
        $goodday->l2   =$rili[36];
        
        
        
        $goodday->save(); 
        exit;  
        }
    }
    /*
     * 拆成小字
     * */
    function actionfenge()
    {   exit(0);
        set_time_limit(0);
    	require_once 'D:\www\root\chief\lib\htmlparse/simple_html_dom.php'; 	
    	$a=strtotime("2013-1-1");
        for($j=0;$j<=2921;$j++){
	        $b=strtotime("+{$j} day", $a);
	        $date=date('Y-n-j',$b);   	
	    	$html = file_get_html("http://www.hdjr.org/{$date}.html");
	    	$element=$html->find('.chiefA',0)->find('ul.NL',0)->find('li');
	        $data=array();
	        $i=0;
	        foreach($element as $k)
	        {
	           $data[]=$k->plaintext;
	        }
	        $num=count($data)/2;
	        for($i=1;$i<=$num;$i++)
	        {
	          $rili[trim(str_replace('：','',$data[2*$i - 2]))]=$data[2*$i-1];
	        }
	        $lan=array(1 =>'公历',2=>'回历',3=>'农历',4=>'胎神占方',5=>'岁次',6=>'彭祖百忌',7=>'五行',8=>'吉神宜趋',9=>'冲煞',10=>'凶神宜忌',11=>'宜',12=>'忌');   
	        $avoid = new Avoid();
	        foreach($lan as $k => $v)
	        {
	          if($k == 5)
	          {
	            $avoid->time       = strtotime($date);
	            $avoid->avoidname  = trim($rili[$v]);
	            $avoid->col        = $k;
	            $avoid->date       = $date;
	            $avoid->save();
	            continue;
	          }
	          $god[$v]=explode(' ', trim($rili[$v]));
	          foreach($god[$v] as $vv)
	          {
	          	if(trim($vv)){
	            $avoid->time       = strtotime($date);
	            $avoid->avoidname  = trim($vv);
	            $avoid->col        = $k;
	            $avoid->date       = $date;
	            $avoid->save();
	          	}
	          }
	        }
        }
        exit;
    }
    
    
    /*
     * 
     * 黄道吉日的数据导入
     * */
    function actiongoodday()
    {
        
    	set_time_limit(0);
    	require_once 'D:\www\root\chief\lib\htmlparse/simple_html_dom.php';
        $a=strtotime("2013-1-1");
        for($j=0;$j<=2921;$j++){
        $b=strtotime("+{$j} day", $a);
        $date=date('Y-n-j',$b);   	
    	$html = file_get_html("http://www.hdjr.org/{$date}.html");
        $element=$html->find('.chiefA',0)->find('ul.NL',0)->find('li');
        $data=array();
        $i=0;
        foreach($element as $k)
        {  
           $data[]=$k->plaintext;           
        }
        $num=count($data)/2;
        for($i=1;$i<=$num;$i++)
        {
          $rili[trim(str_replace('：','',$data[2*$i - 2]))]=$data[2*$i-1];
        }
        $lan=array(1 =>'公历',2=>'回历',3=>'农历',4=>'胎神占方',5=>'岁次',6=>'彭祖百忌',7=>'五行',8=>'吉神宜趋',9=>'冲煞',10=>'凶神宜忌',11=>'宜',12=>'忌');  
        $gongli= explode(' ', trim($rili[$lan[1]]));
        $nongli= explode(' ', trim($rili[$lan[3]]));
        $gongli[0]=str_replace('年','-' , $gongli[0]);
        $gongli[0]=str_replace('月','-' , $gongli[0]);
        $gongli[0]=str_replace('日','' , $gongli[0]);
        $gongli[0]=strtotime($gongli[0]);
        $gongli[0]=date('Y年m月d日',$gongli[0]);
        $goodday = new Exgoodday();
        $goodday->gongli ='公元'.$gongli[0];
        $goodday->nongli ='农历'.$nongli[0].$nongli[1].$nongli[2].' '.$gongli[1].' '.$gongli[2];     
        $goodday->sueici =$rili[$lan[5]].' '.$nongli[3];
        $goodday->wuxing =$rili[$lan[7]];
        $goodday->chong  =$rili[$lan[9]];
        $goodday->taishen  =$rili[$lan[4]];
        $goodday->jishen  =$rili[$lan[8]];
        $goodday->pengzu =$rili[$lan[6]];
        $goodday->yi     =$rili[$lan[11]];
        $goodday->xiongshen  =$rili[$lan[10]];
        $goodday->ji  =$rili[$lan[12]];      
        $goodday->save(); 
        }
    
    }
    
}

